package top.hkyzf.study.leetcode.string;

import org.junit.Test;

/**
 * @author 朱峰
 * @date 2022-2-2 10:06
 */
public class 反转单词前缀_2000 {
    public String reversePrefix(String word, char ch) {
        int index = word.indexOf(ch);
        if (index < 0) {
            return word;
        }
        char[] charArray = word.toCharArray();
        int left = 0;
        int right = index;
        char temp;
        while (left < right) {
            temp = charArray[left];
            charArray[left] = charArray[right];
            charArray[right] = temp;
            left++;
            right--;
        }
        return String.valueOf(charArray);
    }

    @Test
    public void testReversePrefix () {
        String word = "abcdefd";
        char ch = 'd';
        System.out.println(reversePrefix(word, ch));
    }
}
